#include "StdAfx.h"
#include "LocalFileIcon.h"

CImageList* CLocalFileIcon::GetImageList()
{
	SHFILEINFO fileInfo;   
	HIMAGELIST hImgList=NULL;   

	hImgList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), 0, &fileInfo, sizeof(fileInfo), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);   
	if(!hImgList)   
	{   
		return  NULL;   
	}      
	return CImageList::FromHandle(hImgList);
}

int CLocalFileIcon::GetFileIcon(const CString &strFilename)
{
	CString str = strFilename;

	if(str.IsEmpty())
	{
		return 0;
	}

	int iIcon = 0;
	bool bFileCreated = false;

	SHFILEINFO shFi;
	if(!SHGetFileInfo(str, 0, &shFi, sizeof(shFi),SHGFI_ICON |SHGFI_SMALLICON |SHGFI_DISPLAYNAME))
	{
		return iIcon;
	}
	iIcon = shFi.iIcon;
	DestroyIcon(shFi.hIcon);

	return iIcon;
}
